import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  LIST_URL = '/lemon-payment/merchant/info/page',
  DETAIL_URL = '/lemon-payment/merchant/info/detail',
  SAVE_URL = '/lemon-payment/merchant/info/create',
  UPDATE_URL = '/lemon-payment/merchant/info/update',
  DELETE_URL = '/lemon-payment/merchant/info/delete',
  DELETE_BATCH_URL = '/lemon-payment/merchant/info/deleteBatch',
}

/**
 * 商户信息列表
 * @param params
 */
export const pageList = (params) => defHttp.get({url: Api.LIST_URL, params});

/**
 * 商户信息详情
 * @param id
 */
export const getById = (id) => {
  return defHttp.get({url: Api.DETAIL_URL + `/${id}`});
};

/**
 * 保存或者更新商户信息
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? Api.UPDATE_URL : Api.SAVE_URL;
  return defHttp.post({url: url, params});
};

/**
 * 删除商户信息
 * @param id
 * @param reload
 */
export const deleteById = (id, reload) => {
  return defHttp.delete({url: Api.DELETE_URL + `/${id}`}).then(() => {
    reload();
  });
};

/**
 * 批量删除商户信息
 * @param params
 * @param reload
 */
export const deleteBatch = (params, reload) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp
        .delete(
          {
            url: Api.DELETE_BATCH_URL,
            data: params,
          },
          {joinParamsToUrl: true},
        )
        .then(() => {
          reload();
        });
    },
  });
};
